package com.woyou.ui.activity;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import retrofit.RetrofitError;
import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.citaq.ideliver.R;
import com.squareup.picasso.Picasso;
import com.woyou.bean.CodeResult;
import com.woyou.bean.MyAddress;
import com.woyou.bean.Result;
import com.woyou.bean.UserInfo;
import com.woyou.bean.rpc.PhonePwdReq;
import com.woyou.bean.rpc.UpdateUserInfoReq;
import com.woyou.bean.rpc.UploadPicReq;
import com.woyou.service.LocationLoopService;
import com.woyou.service.NetWorkCenter;
import com.woyou.ui.api.IBackEventStrategy;
import com.woyou.ui.component.DateDialog;
import com.woyou.ui.component.DateDialog.DateBtnListener;
import com.woyou.ui.component.EditDialog;
import com.woyou.ui.component.EditDialog.BtnListener;
import com.woyou.ui.component.ErrorHintView;
import com.woyou.ui.component.ErrorHintView.OperateListener;
import com.woyou.ui.component.RoundImageView;
import com.woyou.utils.Dialog;
import com.woyou.utils.eventbus.EventInfoSetup;

import de.greenrobot.event.EventBus;

/**
 * 我的用户信息MyInfoFragment
 * 
 * @author tanglc
 */
@EActivity(R.layout.fm_myinfo)
public class MyInfoActivity extends BaseActivity implements IBackEventStrategy {

	private static final String IMAGE_UNSPECIFIED = "image/*";
	private static final int PHOTO_GRAPH = 1;// 拍照
	private static final int PHOTO_ZOOM = 2; // 缩放
	private static final int PHOTO_RESOULT = 3;// 结果

	Dialog dialog = new Dialog();
	EditDialog userInfoDialog = new EditDialog();
	DateDialog dateDialog = new DateDialog();
	private PopupWindow mPopupWindow;
	private View imageContent;
	
	UserInfo userInfo = null;

	@ViewById(R.id.loading_iv)
	ImageView loading_iv; // 数据加载
	@ViewById(R.id.hintView)
	ErrorHintView mErrorHintView;
	@ViewById(R.id.load_loading)
	RelativeLayout loading; // 正在加载中

	// 头像图标
	@ViewById
	RoundImageView fm_myinfo_userpictext;
	@ViewById
	ImageView pic;
	@ViewById
	ScrollView isscroll;
	@ViewById
	RelativeLayout rl, myback;
	// 头部标题、用户姓名、用户性别、用户生日、绑定手机号码、是否绑定微信、是否绑定微博、是否绑定小米
	@ViewById
	TextView head_title, fm_myinfo_nametext, fm_myinfo_sextext, fm_myinfo_birthdaytext, fm_myinfo_phonetext,
			fm_myinfo_weixintext, fm_myinfo_weibotext, fm_myinfo_mitext;
	// 选择用户头像、输入用户姓名、选择用户性别、选择用户生日、绑定手机、绑定微信、绑定微博、绑定小米、退出当前账户
	@ViewById
	LinearLayout fm_myinfo_userpicbtn, fm_myinfo_namebtn, fm_myinfo_sexbtn, fm_myinfo_birthdaybtn, fm_myinfo_phonebtn,
			fm_myinfo_weixinbtn, fm_myinfo_weibobtn, fm_myinfo_mibtn, fm_myinfo_backaccountbtn, picshow;

	@AfterViews
	public void init() {
		initView();

		// 判断是根新用户信息还是退出当前账号
		userInfoDialog.setBtnListener(new BtnListener() {

			@Override
			public void pressBtn(int id, String str) {
				switch (id) {
				case R.id.ok_button:
					if (!str.equals("fm_myinfo_backaccountbtn")) {
						updateUserInfo();
					} else {
						mUserModel.deleteUserDao();
						List<MyAddress> list = mUserModel.queryAddrList();
						if (list != null) {
							list.clear();
						}
						finish();
						EventBus.getDefault().post(new EventInfoSetup());
					}
					break;
				default:
					break;
				}
			}
		});

		// 更新用户生日
		dateDialog.setDateBtnListener(new DateBtnListener() {

			@Override
			public void pressDateBtn(int id) {
				switch (id) {
				case R.id.ok_button:
					updateUserInfo();
					break;

				default:
					break;
				}
			}
		});
	}

	// 关闭个人设置界面、选择用户头像、头像大图、退出头像大图
	@Click({ R.id.myback, R.id.fm_myinfo_userpicbtn, R.id.fm_myinfo_userpictext, R.id.picshow, R.id.fm_myinfo_namebtn,
			R.id.fm_myinfo_sexbtn, R.id.fm_myinfo_birthdaybtn, // 输入用户姓名、选择用户性别、选择用户生日
			R.id.fm_myinfo_weixinbtn, // 绑定手机、绑定微信
			R.id.fm_myinfo_weibobtn, R.id.fm_myinfo_mibtn, // 绑定微博、绑定小米
			R.id.fm_myinfo_backaccountbtn })
	void loginOnClick(View view) {
		switch (view.getId()) {
		case R.id.myback: 
			// 退出用户信息修改界面
			backOperate();
			break;
			
		case R.id.fm_myinfo_userpicbtn: 
			// 设置用户头像
			showImageSelect();
			break;
			
		case R.id.fm_myinfo_userpictext: 
			// 显示用户头像大图
			if (userInfo.getPicUrl() != null && !userInfo.getPicUrl().equals("")) {
				picshow.setVisibility(View.VISIBLE);
			} else {
				showImageSelect();
			}
			break;
			
		case R.id.picshow: 
			// 显示用户头像大图
			picshow.setVisibility(View.GONE);
			break;
			
		case R.id.fm_myinfo_namebtn: 
			// 输入用户姓名
			userInfoDialog.Dialog(mActivity, fm_myinfo_nametext, R.id.fm_myinfo_nametext, "姓名", "isEdit");
			break;
			
		case R.id.fm_myinfo_sexbtn: 
			// 选择用户性别
			userInfoDialog.Dialog(mActivity, fm_myinfo_sextext, R.id.fm_myinfo_sextext, "性别", "isRadio");
			break;
			
		case R.id.fm_myinfo_birthdaybtn: 
			// 选择用户生日
			dateDialog.showDatePicker(mActivity, fm_myinfo_birthdaytext, R.id.fm_myinfo_birthdaytext);
			break;
			
		case R.id.fm_myinfo_weixinbtn: 
			// 绑定微信
			dialog.Toast(mActivity, "微信绑定成功！");
			break;
			
		case R.id.fm_myinfo_weibobtn: 
			// 绑定新浪微博
			dialog.Toast(mActivity, "新浪微博绑定成功！");
			break;
			
		case R.id.fm_myinfo_mibtn: 
			// 小米绑定
			dialog.Toast(mActivity, "小米绑定成功！");
			break;
			
		case R.id.fm_myinfo_backaccountbtn: 
			// 退出当前账号
			userInfoDialog.Dialog(mActivity, fm_myinfo_phonetext, R.id.fm_myinfo_phonetext, "", "isDialog");
			break;
		default:
			break;
		}
	}

	@Click({ R.id.load_retry, R.id.wifi_retry })
	void failureRetry() {
		loadUserInfo();
	}

	/**
	 * 账户信息界面初始化
	 * 
	 * @author tanglec 下午3:18:12
	 */
	public void initView() {
		head_title.setText("账户信息");

		initImageSelect();

		loadUserInfo();

	}

	/**
	 * 加载用户信息
	 */
	@Background
	void loadUserInfo() {
		if (!NetWorkCenter.isNetworkConnected(this)) {
			runOnUI(new Runnable() {
				@Override
				public void run() {
					showViewById(2);
				}
			});
			return;
		}
		showViewById(4);
		try {
			userInfo = mUserModel.getUserInfo();
			PhonePwdReq phonePwdReq = new PhonePwdReq();

			if (LocationLoopService.getInstance(mContext).getChosenAddr() != null) {
				phonePwdReq.setLat(LocationLoopService.getInstance(mContext).getChosenAddr().getLat());
				phonePwdReq.setLng(LocationLoopService.getInstance(mContext).getChosenAddr().getLng());
			} else {
				if (mBaiduLocationService.getLastLocation() != null) {
					phonePwdReq.setLat(mBaiduLocationService.getLastLocation().getLatitude() + "");
					phonePwdReq.setLng(mBaiduLocationService.getLastLocation().getLongitude() + "");
				} else {
					phonePwdReq.setLat("");
					phonePwdReq.setLng("");
				}
			}

			phonePwdReq.setPwd(userInfo.getPwd());
			phonePwdReq.setuId(userInfo.getuId());

			Result<UserInfo> result = mUserModel.v2_1queryUserInfo(phonePwdReq);
			refreshUI(result);
		} catch (RetrofitError e) {
			switch (e.getKind()) {
			case HTTP:
				showViewById(6);
				return;
			case CONVERSION:
				showViewById(3);
				return;
			case NETWORK:
				showViewById(6);
				return;
			case UNEXPECTED:
				showViewById(3);
				return;
			}
		} finally {
			hideLoading();
		}
	}

	@UiThread
	void refreshUI(Result<UserInfo> result) {
		if (result != null && result.getCode() == 1) {
			showViewById(1);
			userInfo = result.getData();
			if (userInfo != null && userInfo.getuId() != null) {

				if (userInfo.getPicUrl() != null
						&& !userInfo.getPicUrl().equals("")) {
					refreshIMG(userInfo.getPicUrl(), userInfo.getBigPicUrl());
				} else {
					fm_myinfo_userpictext.setImageResource(R.raw.touxiang);
				}

				if (userInfo.getName() != null
						&& !userInfo.getName().equals("")) {
					fm_myinfo_nametext.setText(userInfo.getName());
				} else {
					fm_myinfo_nametext.setText(userInfo.getuId());
				}

				if (userInfo.getSex() == 2) {
					fm_myinfo_sextext.setText("男");
				} else if (userInfo.getSex() == 1) {
					fm_myinfo_sextext.setText("女");
				} else {
					fm_myinfo_sextext.setText("--");
				}

				if (userInfo.getBirth() == null
						|| userInfo.getBirth().length() == 0) {
					fm_myinfo_birthdaytext.setText("");
				} else {
					fm_myinfo_birthdaytext.setText(userInfo.getBirth());
				}

				fm_myinfo_phonetext.setText(userInfo.getPhone());
				fm_myinfo_weixintext.setText("已绑定");
				fm_myinfo_weibotext.setText("已绑定");
				fm_myinfo_mitext.setText("未绑定");

			} else {
				fm_myinfo_userpictext.setImageResource(R.raw.touxiang);
				fm_myinfo_nametext.setText("");
				fm_myinfo_sextext.setText("");
				fm_myinfo_birthdaytext.setText("");
				fm_myinfo_phonetext.setText("未绑定");
				fm_myinfo_weixintext.setText("未绑定");
				fm_myinfo_weibotext.setText("未绑定");
				fm_myinfo_mitext.setText("未绑定");
			}
		} else if (result != null && result.code == -3) {
			finish();
			
		} else {
			showViewById(3);
		}
	}

	/**
	 * 显示个人详细信息：1 显示断网：2 显示加载数据失败：3 显示加载中：4 网络超时：6
	 */
	@UiThread
	public void showViewById(int i) {
		hideLoading();
		isscroll.setVisibility(View.GONE);
		switch (i) {
		case 1:
			stopRotateAnim();
			isscroll.setVisibility(View.VISIBLE);
			mErrorHintView.close();
			break;
		case 2:
			stopRotateAnim();
			mErrorHintView.netError(new OperateListener() {

				@Override
				public void operate() {
					loadUserInfo();
				}
			});
			break;
		case 3:
			stopRotateAnim();
			mErrorHintView.loadFailure(new OperateListener() {

				@Override
				public void operate() {
					loadUserInfo();
				}
			});
			break;
		case 4:
			mErrorHintView.close();
			loading.setVisibility(View.VISIBLE);
			showLoading(loading_iv);
			break;
		case 6:
			stopRotateAnim();
			mErrorHintView.timeOut(new OperateListener() {

				@Override
				public void operate() {
					mBaiduLocationService.startLocation();

				}
			});
			break;
		}
	}


	/**
	 * 向服务器请求更新用户数据
	 */
	@Background
	void updateUserInfo() {
		if (!NetWorkCenter.isNetworkConnected(this)) {
			showToast("请检查你的网络!");
			return;
		}
		showProgressDialog();
		try {
			// 设置请求参数
			UserInfo userInfo = mUserModel.getUserInfo();
			UpdateUserInfoReq updateUserInfo = new UpdateUserInfoReq();
			updateUserInfo.setuId(userInfo.getuId());
			updateUserInfo.setNick(fm_myinfo_nametext.getText().toString());
			updateUserInfo.setName(fm_myinfo_nametext.getText().toString());
			if (fm_myinfo_sextext.getText().toString().equals("男")) {
				updateUserInfo.setSex(2);
			} else if (fm_myinfo_sextext.getText().toString().equals("女")) {
				updateUserInfo.setSex(1);
			} else {
				updateUserInfo.setSex(0);
			}
			updateUserInfo.setBirth(fm_myinfo_birthdaytext.getText().toString());
			updateUserInfo.setPhone(fm_myinfo_phonetext.getText().toString());
			updateUserInfo.setPwd(userInfo.getPwd());
			CodeResult result = mUserModel.updateUserInfo(updateUserInfo);
			dismissProgressDialog();
			// 解析返回数据显示View
			showView(result);
		} catch (RetrofitError e) {
			dismissProgressDialog();
			switch (e.getKind()) {
			case HTTP:
				return;
			case CONVERSION:
				return;
			case NETWORK:
				return;
			case UNEXPECTED:
				return;
			}
		}
	}

	@UiThread
	void showView(CodeResult result) {
		if (result != null && result.code == 1) {
			showToast(result.msg);
			EventBus.getDefault().post(new EventInfoSetup());
			
		} else if (result != null && result.code == -3) {
			finish();
			dialog.LoginToast(mContext, result.msg);
			
		} else if (result != null) {
			showToast(result.msg);
		}
		
		loadUserInfo();

		// UserInfo userInfo = userController.getUserInfo();
		// fm_myinfo_nametext.setText(userInfo.getName());
		// if (userInfo.getPicUrl() != null && !userInfo.getPicUrl().equals(""))
		// {
		// refreshIMG(userInfo.getPicUrl(), userInfo.getBigPicUrl());
		// } else {
		// fm_myinfo_userpictext.setImageResource(R.raw.touxiang);
		// }
		// if (userInfo.getSex() == 2) {
		// fm_myinfo_sextext.setText("男");
		// } else if (userInfo.getSex() == 1) {
		// fm_myinfo_sextext.setText("女");
		// } else {
		// fm_myinfo_sextext.setText("--");
		// }
		// fm_myinfo_birthdaytext.setText(userInfo.getBirth());
		// fm_myinfo_phonetext.setText(userInfo.getPhone());
	}

	Intent intent;

	@SuppressLint("NewApi")
	private void initImageSelect() {
		imageContent = View.inflate(mActivity, R.layout.get_image, null);
		// 拍照
		imageContent.findViewById(R.id.take_photo).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
				intent.putExtra(MediaStore.EXTRA_OUTPUT,
						Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "temp.jpg")));
				startActivityForResult(intent, PHOTO_GRAPH);
				if (mPopupWindow != null && mPopupWindow.isShowing()) {
					mPopupWindow.dismiss();
				}
			}
		});
		
		// 相册选择
		imageContent.findViewById(R.id.upload).setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				intent = new Intent(Intent.ACTION_PICK, null);
				intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_UNSPECIFIED);
				startActivityForResult(intent, PHOTO_ZOOM);
				if (mPopupWindow != null && mPopupWindow.isShowing()) {
					mPopupWindow.dismiss();
				}
			}
		});
		
		// 取消
		imageContent.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mPopupWindow.dismiss();
			}
		});
		
		// 取消
		imageContent.findViewById(R.id.get_imagelayout).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mPopupWindow.dismiss();
			}
		});
		
		// 重写onKeyListener
		imageContent.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				if (keyCode == KeyEvent.KEYCODE_BACK) {
					mPopupWindow.dismiss();
					mPopupWindow = null;
					return true;
				}
				return false;
			}
		});
	}

	/**
	 * show出选项卡 tanglc
	 */
	private void showImageSelect() {
		if (mPopupWindow != null && mPopupWindow.isShowing()) {
			mPopupWindow.dismiss();
		}
		mPopupWindow = new PopupWindow(imageContent, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		mPopupWindow.setFocusable(true);
		mPopupWindow.setBackgroundDrawable(new PaintDrawable(R.color.transparentblack));
		mPopupWindow.showAtLocation(rl, Gravity.BOTTOM, 0, 0);
	}

	String path = null;

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		// 拍照
		if (requestCode == PHOTO_GRAPH && resultCode == -1) {
			// 设置文件保存路径
			File picture = new File(Environment.getExternalStorageDirectory() + "/temp.jpg");
			path = picture.getPath();
			if (path != null && !path.equals("")) {
				startPhotoZoom(Uri.fromFile(picture));
			}
		}
		// 读取相册缩放图片
		if (requestCode == PHOTO_ZOOM && data != null) {
			Uri originalUri = data.getData(); // 获得图片的uri
			String[] proj = { MediaStore.Images.Media.DATA };
			@SuppressWarnings("deprecation")
			Cursor cursor = mActivity.managedQuery(originalUri, proj, null, null, null);
			// Cursor cursor = mContext.getContentResolver().query(originalUri,
			// proj, null,
			// null, null);
			if (cursor != null) {
				int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
				cursor.moveToFirst();
				path = cursor.getString(column_index);
				startPhotoZoom(data.getData());
			} else {
				showToast("读取文件失败");
			}
		}
		// 处理结果
		if (requestCode == PHOTO_RESOULT && data != null) {
			Bundle extras = data.getExtras();
			if (extras != null) {
				Bitmap photo = extras.getParcelable("data");
				try {
					// photo = compressImage(photo);
					saveImage(photo, path);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	};

	/**
	 * 收缩图片
	 * 
	 * @param uri
	 */
	public void startPhotoZoom(Uri uri) {
		Intent intent = new Intent("com.android.camera.action.CROP");
		intent.setDataAndType(uri, IMAGE_UNSPECIFIED);
		intent.putExtra("crop", "true");
		// aspectX aspectY 是宽高的比例
		intent.putExtra("aspectX", 1);
		intent.putExtra("aspectY", 1);
		// outputX outputY 是裁剪图片宽高
		intent.putExtra("outputX", 160);
		intent.putExtra("outputY", 160);
		intent.putExtra("return-data", true);
		startActivityForResult(intent, PHOTO_RESOULT);
	}

	private Bitmap compressImage(Bitmap image) {

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		image.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 质量压缩方法，这里100表示不压缩，把压缩后的数据存放到baos中
		int options = 100;
		while (baos.toByteArray().length / 1024 > 1024) { // 循环判断如果压缩后图片是否大于1M,大于继续压缩
			baos.reset();// 重置baos即清空baos
			image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%，把压缩后的数据存放到baos中
			options -= 10;// 每次都减少10
		}
		ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中
		Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);// 把ByteArrayInputStream数据生成图片
		return bitmap;
	}

	/**
	 * 保存头像 tanglc
	 * 
	 * @param bmp
	 * @throws IOException
	 */
	private void saveImage(Bitmap bmp, final String path) throws IOException {
		File fImage = new File(Environment.getExternalStorageDirectory(), "testPng");
		fImage.createNewFile();
		FileOutputStream iStream = new FileOutputStream(fImage);
		bmp.compress(CompressFormat.PNG, 100, iStream);
		iStream.close();
		uploadImage(fImage.getPath());
	}

	/**
	 * 上传头像 tanglc
	 */
	@Background
	void uploadImage(String path) {
		showProgressDialog();
		UserInfo userInfo = mUserModel.getUserInfo();
		UploadPicReq uploadPicReq = new UploadPicReq();
		uploadPicReq.setId(userInfo.getuId());
		uploadPicReq.setTypeId(1);
		try {
			Result<UserInfo> result = mUserModel.v2_1uploadUserPic(uploadPicReq, path);
			showView(result);
		} catch (Exception e) {
			// TODO: handle exception
			showToast("网络异常，请检查网络是否已连接，重新上传头像");
			dismissProgressDialog();
		}
	}

	@UiThread
	void showView(Result<UserInfo> result) {
		dismissProgressDialog();
		if (result.code == 1) {
			showToast(result.msg);
			loadUserInfo();
			
		} else if (result != null && result.code == -3) {
			finish();
			dialog.LoginToast(mContext, result.msg);
			
		} else if (result != null) {
			showToast(result.msg);
		}
	}

	/**
	 * 刷新我的汇总页面头像图标 tanglc
	 * 
	 * @param url
	 */
	@UiThread
	void refreshIMG(String url, String bigUrl) {
		try {
			Picasso.with(mContext).load(url).into(fm_myinfo_userpictext);
			Picasso.with(mContext).load(bigUrl).into(pic);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public interface ImageCallback {
		public void imageLoaded(Drawable imageDrawable, String imageUrl);
	}

	@Override
	public boolean backOperate() {
		if (picshow.getVisibility() == View.VISIBLE) {
			picshow.setVisibility(View.GONE);
			
		} else {
			finish();
		}
		return true;
	}

	RotateAnimation rotateAnimation;

	@UiThread
	void startRotateAnim() {
		loading.setVisibility(View.VISIBLE);
		// 创建一个RotateAnimation对象（以某个点为圆心旋转360度）
		// 相对于自己的360度旋转
		if (rotateAnimation == null) {
			rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
					0.5f);
			rotateAnimation.setDuration(1000);
			rotateAnimation.setRepeatCount(-1); // ndroid:repeatCount
												// 重复的次数，默认为0，必须是int，可以为-1表示不停止
			rotateAnimation.setInterpolator(new LinearInterpolator());
			loading_iv.setAnimation(rotateAnimation);
		}
		// rotateImg.startAnimation(rotateAnimation);
		rotateAnimation.start();
	}

	@UiThread
	void stopRotateAnim() {
		if (rotateAnimation != null) {
			rotateAnimation.cancel();
		}
	}
	

}
